package com.wochao.common.exception;

import com.wochao.common.result.ResultCodeEnum;
import lombok.Data;

/**
 * 自定义的异常处理：捕获到异常后，便会直接为前端返回响应结果
 */
@Data
public class ReturnToFrontException extends RuntimeException {
    //异常状态码
    private Integer code;

    /**
     * 通过异常信息和异常状态码创建异常对象
     *
     * @param message
     * @param code
     */
    public ReturnToFrontException(String message, Integer code) {
        super(message);
        this.code = code;
    }

    /**
     * 通过异常的响应结果枚举对象来创建异常对象
     * @param resultCodeEnum
     */
    public ReturnToFrontException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "ReturnToFrontException{" +
                "code=" + code +
                "message=" + this.getMessage() +
                '}';
    }
}
